﻿using System;
using MyAMS.WebServer.Models;

namespace MyAMS.WebServer
{
    /// <summary>
    /// 辅助类型
    /// </summary>
    public static class Helper
    {       
        /// <summary>
        /// 记录日志信息
        /// </summary>
        /// <param name="type">日志类型</param>
        /// <param name="title">日志标题</param>
        /// <param name="content">日志内容</param>
        public static void Log(LogType type, string title, string content)
        { 
        
        }

        /// <summary>
        /// 如果指定的条件为True则抛出异常
        /// </summary>
        /// <param name="condition">判定条件</param>
        /// <param name="message">消息</param>
        public static void Assert(bool condition, string message)
        {
            if (!condition)
            {
                Throw(message);
            }
        }

        /// <summary>
        /// 抛出异常消息
        /// </summary>
        /// <param name="message">消息</param>
        public static void Throw(string message)
        {
            throw new WebServerException(message);
        }

        /// <summary>
        /// 克隆
        /// </summary>
        /// <typeparam name="T">所要克隆对象的类型</typeparam>
        /// <param name="source">所要克隆对象</param>
        /// <returns>对象复本</returns>
        public static T Clone<T>(T source) where T : ICloneable
        {
            T t = default(T);
            if (source != null)
            {
                object o = source.Clone();
                if (o != null && o is T)
                {
                    t = (T)o;
                }
            }
            return t;
        }
    }
}
